#ifndef __COMMON_TYPE_H_
#define __COMMON_TYPE_H_


/**Notice that
 * unsigned long is
 *  4 byte in 32-bit machine,
 *  8 byte in 64-bit machine.
 */
typedef unsigned long word;
typedef unsigned char boolean;
typedef void* object;
typedef void* address;
typedef void* StackPointer;
typedef void (*executable)(object);
typedef int (*runable)(object);
typedef unsigned long long u64;
typedef unsigned u32;

#define True  ((boolean)1)
#define False ((boolean)0)
#ifndef NULL
#define NULL  ((void*) 0)
#endif

//cast object as type
#define CAST_AS(Type, obj) ((Type)(obj))

//caculate the offset of a member, Type must be pointer style
#define OFFSET_OF(Type, member) (long)&(CAST_AS(Type,0)->member)

//get the container of a member from the member's address e.g. ptr
#define CONTAINER_OF(Type, member, memptr) \
        CAST_AS(Type, (void*)memptr - OFFSET_OF(Type,member))


#define __CHECK_FORMAT_STR__(a,b) __attribute__ ((format (printf, a, b)))
#define __CHECK__PRINTF_FORMAT__  __CHECK_FORMAT_STR__(1, 2)

#endif//__COMMON_TYPE_H_